﻿using System.Diagnostics;
using System.ServiceModel.Channels;
using System.Threading;
using MockingBird.Simulator.Interceptors.Wcf.Contracts;

namespace MockingBird.Simulator.Interceptors.Wcf.SimulatorTester
{
    public class DuplexCallbackHandler : IOneWay
    {
        internal string ActionToVerify { get; set; }
        internal AutoResetEvent ReceivedEvent = new AutoResetEvent(false);

        public DuplexCallbackHandler(string actionToVerify)
        {
            this.ActionToVerify = actionToVerify;
        }

        #region IOneWay Members

        public void ProcessMessage(Message message)
        {
            DummyMessage dm = message.GetBody<DummyMessage>();
            Trace.Assert(null != dm, "DummyMessage was null.");

            if (null != this.ActionToVerify)
            {
                Trace.Assert(this.ActionToVerify.Equals(dm.Action), "Incorrect DummyMessage.Action");
            }
            ReceivedEvent.Set();
        }

        #endregion
    }
}
